package com.study.webapp.leetcode;

import java.util.Collection;

/**
 * 最后一个单词的长度
 * https://leetcode.cn/problems/length-of-last-word/
 */
public class Leet_58 {

	public static void main(String[] args) {
//		String s = "   fly me   to   the moon  ";
//		System.out.println(lengthOfLastWord(s));
		int x = 3;
		int y = 3;
		String a = "a";
		String b = "a";
		System.out.println(x==y);
		System.out.println(a == b);
		System.out.println(Leet_58());
	}

	public Leet_58() {

	}

	private static int Leet_58() {
		return 1;
	}

	public static int lengthOfLastWord(String s) {
		if (s.length() == 0) {
			return 0;
		}
		char[] a = s.toCharArray();
		int len = 0;
		char c = ' ';
		for (int i = a.length-1; i >= 0; i--) {
			if (a[i] != c) {
				len++;
			}
			if (a[i] == c && len > 0) {
				break;
			}
		}
		return len;
	}

}
